package com.winning.cqs.pregnantbabycare_cqs_v1.db;


import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import com.winning.cqs.pregnantbabycare_cqs_v1.table.Alarm.AlarmTable;
import com.winning.cqs.pregnantbabycare_cqs_v1.table.Comment.CommentTable;
import com.winning.cqs.pregnantbabycare_cqs_v1.table.Friend.FriendTable;
import com.winning.cqs.pregnantbabycare_cqs_v1.table.Talk.TalkTable;
import com.winning.cqs.pregnantbabycare_cqs_v1.table.User.UserTable;

public class DataBaseHelper extends SQLiteOpenHelper {

	static final String DATABASE_NAME = "chat.db";
	static final int VERSION = 1;
	private static DataBaseHelper mInstance = null;

	public DataBaseHelper(Context context) {
		super(context, DATABASE_NAME, null, VERSION);
	}

	public static synchronized DataBaseHelper getInstance(Context context) {
		if (mInstance == null) {
			mInstance = new DataBaseHelper(context);
		}
		return mInstance;
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		try {
			db.execSQL(FriendTable.TABLE_CREATESQL);
			db.execSQL(UserTable.TABLE_CREATESQL);
			db.execSQL(TalkTable.TABLE_CREATESQL);
			db.execSQL(CommentTable.TABLE_CREATESQL);
			db.execSQL(AlarmTable.TABLE_CREATESQL);
		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		// TODO Auto-generated method stub
		db.execSQL("DROP TABLE IF EXISTS " + FriendTable.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + UserTable.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + TalkTable.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + CommentTable.TABLE_NAME);
		db.execSQL("DROP TABLE IF EXISTS " + AlarmTable.TABLE_NAME);
		onCreate(db);

	}

}
